//
//  WKVisitorViewController.swift
//  WKweiBo
//
//  Created by 阿拉斯加的狗 on 15/12/6.
//  Copyright © 2015年 阿拉斯加的🐶. All rights reserved.
//

import UIKit

class WKVisitorViewController: UITableViewController {

    //定义一个访客属性
    var visitor: visitorView?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

     
    }

    //定义一个标示判断属性
    private var uesrLogon = UserAccountViewModel.sharedUserAccount.userLogin
    
    override func loadView() {
        
        //判断加载视图的选择
        uesrLogon ? super.loadView() : setUpVisitorView()
        
    }
    
    private func setUpVisitorView(){
    
        visitor = visitorView()
        
        view = visitor
        
        //设置按钮监听事件
        visitor?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        visitor?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        //增加导航按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "visitorViewDidLogin")
        
    
    }


}


extension WKVisitorViewController {

        //注册
    func visitorViewDidRegister(){
        
        print("注册")
        
    }
    
        //登陆
    func visitorViewDidLogin(){
    
        //modal到登陆界面
        let vc = OAuthViewController()
        
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    
    }


}

